eratosthenis[n_] := Module[{primes = Table[i, {i, 1, n}], p = 2,c=0},
	Print["loop ",c,":"," primes = ", primes, ", p = ", p];
	While[ p!= n+1,
		  c++;
 		 Do[ primes[[i]] = 1, {i, 2p, n, p} ];
		  p = p + 1;
		  While[ p != n+1 && primes[[p]]==1, p = p+1];
		  Print["loop ",c,":"," primes = ", primes, ", p = ", p];	];
	Select[primes, (# != 1)&]]

eratosthenis[10]

eratosthenis1[n_] := 
Module[{lst = Table[i, {i, 2, n}], p,c=0,primes={}},
  Print["Loop ",c, ":"];
  Print["lst = ", lst];
  Print["primes = ",primes ];
	While[ lst!={},
	 		p = lst[[1]];
 		  lst=Select[lst,Mod[#,p]!=0&];
			AppendTo[primes, p];
			c++;
       Print["Loop ",c, ":"];
       Print["lst = ", lst];
       Print["primes = ",primes ];]; 
		primes]

eratosthenis1[29]